package com.shanpin.shebao.web.module.rong360;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.shanpin.shebao.web.db.AppDbRepository;
import com.shanpin.shebao.web.module.rong360.model.TianjiData;

@Repository
public class TianjiDao {

	@Autowired
	private AppDbRepository jdbc;
	
	public TianjiData get(int userId, String idcard, String city) {
		final String sql = "SELECT * FROM t_tianji_data WHERE user_id=? AND id_card=? AND city=? LIMIT 1";
		return jdbc.queryT(sql, TianjiData.MAPPER, userId, idcard, city);
	}
	
	public int saveFund(int userId, String idcard,  String city, String name, String phone,
			String fundComName, String fundComCode, int fundBaseMoney,  int fundMonthMoney, 
			int fundPer, int fundCom, String fundBeginMonth, String fundEndMonth, String fundLackMonth) {
		final String sql = "INSERT INTO t_tianji_data (user_id, id_card, city, name, phone, "
							+" fund_com_name, fund_com_code, fund_base_money, fund_month_money, "
							+" fund_per, fund_com, fund_begin_month, fund_end_month, fund_lack_month, fund_query_time) VALUES "
							+"(?,?,?,?,?,  ?,?,?,?,   ?,?,?,?,?,?)";
		return jdbc.insert(sql, "tid", userId, idcard, city, name, phone, 
				fundComName, fundComCode, fundBaseMoney, fundMonthMoney,
				fundPer, fundCom, fundBeginMonth, fundEndMonth, fundLackMonth, new Date());
	}
	
	public boolean updateFund(int tid, String name, String phone,
			String fundComName, String fundComCode, int fundBaseMoney,  int fundMonthMoney, 
			int fundPer, int fundCom, String fundBeginMonth, String fundEndMonth, String fundLackMonth) {
		final String sql = "UPDATE t_tianji_data SET name=?, phone=?, "
				+" fund_com_name=?, fund_com_code=?, fund_base_money=?, fund_month_money=?, "
				+" fund_per=?, fund_com=?, fund_begin_month=?, fund_end_month=?, fund_lack_month=?, fund_query_time=? WHERE tid=?";
		return jdbc.update(sql, name, phone, 
				fundComName, fundComCode, fundBaseMoney, fundMonthMoney,
				fundPer, fundCom, fundBeginMonth, fundEndMonth, fundLackMonth, new Date(), tid);
	}
	
	public int saveInsure(int userId, String idcard,  String city, String name, String phone,
			String insureComName, String insureComCode, int insurePer, int insureCom,
			String insureBeginMonth, String insureEndMonth, String insurePensionLackMonth, String insureMedicalLackMonth
			) {
		final String sql = "INSERT INTO t_tianji_data (user_id, id_card, city, name, phone, "
				+" insure_com_name, insure_com_code, insure_per, insure_com, "
				+" insure_begin_month, insure_end_month, insure_pension_lack_month, insure_medical_lack_month, insure_query_time) VALUES "
				+"(?,?,?,?,?,  ?,?,?,?,   ?,?,?,?,?)";
		return jdbc.insert(sql, "tid", userId, idcard, city, name, phone, 
				insureComName, insureComCode, insurePer, insureCom,
				insureBeginMonth, insureEndMonth, insurePensionLackMonth, insureMedicalLackMonth, new Date());
	}
	
	public boolean updateInsure(int tid, String name, String phone,
			String insureComName, String insureComCode, int insurePer, int insureCom,
			String insureBeginMonth, String insureEndMonth, String insurePensionLackMonth, String insureMedicalLackMonth
			) {
		final String sql = "UPDATE t_tianji_data SET name=?, phone=?, "
				+" insure_com_name=?, insure_com_code=?, insure_per=?, insure_com=?, "
				+" insure_begin_month=?, insure_end_month=?, insure_pension_lack_month=?, insure_medical_lack_month=?, insure_query_time=? WHERE tid=?";
		return jdbc.update(sql, name, phone, 
				insureComName, insureComCode, insurePer, insureCom,
				insureBeginMonth, insureEndMonth, insurePensionLackMonth, insureMedicalLackMonth, new Date(), tid);
	}
}
